home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7723 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: debbie.ee.queensu.ca!majeed
  2. From: majeed@qucdntri.ee.queensu.ca
  3. Newsgroups: comp.lang.c
  4. Subject: [Q] Help. Initializing crashes program!!!
  5. Date: 28 Feb 96 08:44:28 -0500
  6. Organization: Queen's University EE Department
  7. Message-ID: <1996Feb28.084428.1@debbie.ee.queensu.ca>
  8. NNTP-Posting-Host: debbie.ee.queensu.ca
  9.  
  10. Hello.
  11.  
  12. Alright, here's are some definitions:
  13.  
  14. #define N 8
  15. #define L 13
  16.  
  17. typedef struct
  18. {
  19.     float I[L],Q[L];
  20. } f_short_array;
  21.  
  22. Here's a subroutine:
  23. void PROC1(void)
  24. {
  25.     int m,j;
  26.     ... (other declarations)
  27.     static f_short_array poly_reg[N];
  28.  
  29. /* initializing */
  30.     for (m = 0; m < N; m++)
  31.     {
  32.         for (j = 0; j < L; j++)
  33.         {
  34.             poly_reg[m].I[j] = 0.0;
  35.             poly_reg[m].Q[j] = 0.0;
  36.         }
  37.     }
  38.  
  39.     ... (more code)
  40.  
  41. /* shifting */
  42.     for (m = 0; m < N; m++)
  43.     {
  44.         for (j = L-1; j > 0; j--)
  45.         {
  46.             poly_reg[m].I[j] = poly_reg[m].I[j-1];
  47.             poly_reg[m].Q[j] = poly_reg[m].Q[j-1];
  48.         }
  49.     }
  50.  
  51.     ... (more code)
  52. }
  53.  
  54. Why is it that if I leave the initialization as above, the program crashes
  55. at run-time when there were no compiler/linker warnings or errors?  But,
  56. when I comment that whole section out, i.e. no array clearing, the program
  57. doesn't crash.  I don't get it.  Data is still being assigned to the
  58. elements of poly_reg later on in the program and that doesn't make the
  59. program crash!  Is this a memory-related problem.  I don't see how.  I
  60. counted the total number of bytes that all my arrays (from the whole
  61. proram) sum up to and that number was about 20000.  When I run this
  62. program on a VAX I get an error which goes something like "Access
  63. Violation".
  64.  
  65. That's what I hate about C.  A problem which seems to occur in one place may
  66. be caused by a problem elsewhere.  Could someone please advice me on what
  67. the bug is and how I can fix it?  Thanks in advance.
  68.